package io.github.harmonly.mapper;

import io.github.harmonly.entity.Apply;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ApplyMapper {

    @Select("select * from apply where sender = #{sender} and type = #{type} and state = 'pending'")
    Apply isExist(Apply apply);

    @Select("select * from apply where sender = #{uid}")
    List<Apply> getAppliesBySender(int uid);

    @Select("select * from apply where receiver = #{uid}")
    List<Apply> getAppliesByReceiver(int uid);

    @Select("select * from apply where apid = #{apid}")
    Apply getApply(int apid);

    @Select("select * from apply")
    List<Apply> getApplies();

    @Insert("insert into apply(sender, type, date, state, content) VALUES (#{sender}, #{type}, #{date}, #{state}, #{content})")
    int addApply(Apply apply);

    @Insert("insert into apply(sender, receiver, type, date, state, content) VALUES (#{sender}, #{receiver}, #{type}, #{date}, #{state}, #{content})")
    int addApplyToReceiver(Apply apply);

    @Delete("delete apply from apply where apid = #{apid}")
    int deleteApply(int apid);

    @Update("update apply set state = #{state}, feedback = #{feedback} where apid = #{apid}")
    int editApply(Apply apply);
}
